//
//  NewsInfoViewController.m
//  DA_V
//
//  Created by 周季阳 on 15/4/28.
//  Copyright (c) 2015年 zhouhai. All rights reserved.
//

#import "NewsInfoViewController.h"
#import "InterFace.h"
#import "UIViewAdditions.h"
#import "AccountTableViewCell.h"
#import "DetailsWebViewController.h"
#import "YoungAllData.h"
#import "GMDCircleLoader.h"

@interface NewsInfoViewController ()<YoungDelegate>
@property(nonatomic,retain)NSMutableArray *zArrayData;
@end

static NSString *newsCell = @"Cell";

@implementation NewsInfoViewController
@synthesize tableView,array,zArrayData;
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBarHidden=YES;
    self.view.backgroundColor = [self colorWithHexString:@"#F5F5F5"];
    [self initNav];
    navTitle.text = @"培训";
    YoungAllData *data = [[YoungAllData alloc]init];
    data.delegate = self;
    [data gainTrain:@"1" andPerPage:@"15"];
    [GMDCircleLoader setOnView:self.view withTitle:@"加载中···" animated:YES];

}
#pragma mark - 培训列表回调
-(void)train:(NSDictionary *)sign{
    [GMDCircleLoader hideFromView:self.view animated:YES];
    if ([[sign objectForKey:@"status"] isEqualToString:@"success"]) {
    zArrayData = [[NSMutableArray alloc]initWithArray:[sign objectForKey:@"data"]];
    [self initUI];
    }else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:[sign objectForKey:@"reason"] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];

    }
}
#pragma mark - 培训列表回调失败
-(void)requistFail{

    [GMDCircleLoader hideFromView:self.view animated:YES];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"网络异常,无法加载数据" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
}
#pragma mark - 返回
-(void)clickBackBtn{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - initUI
-(void)initUI{
    tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,navView.bottom, self.view.frame.size.width, self.view.frame.size.height-65-44)];
    tableView.backgroundColor = [UIColor clearColor];
    
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.separatorColor = [UIColor clearColor];
    [self.view addSubview:tableView];
    
    [tableView registerClass:[AccountTableViewCell class] forCellReuseIdentifier:newsCell];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return [zArrayData count];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 40;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    AccountTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:newsCell];
    cell.titleLabel.text = [[zArrayData objectAtIndex:indexPath.row] objectForKey:@"Subject"];
    cell.backgroundColor = [UIColor clearColor];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    //    NSArray *arr = [NSArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5", nil];
    
    DetailsWebViewController *detail = [[DetailsWebViewController alloc] init];
    self.hidesBottomBarWhenPushed = YES;
    detail.courseIDStr = [[zArrayData objectAtIndex:indexPath.row] objectForKey:@"CourseID"];
    [self.navigationController pushViewController:detail animated:YES];
    
    //  [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
